package com.wc.blue_bridge_history.Java14B.F_买二赠一;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/3/11 10:50
 * @description https://www.lanqiao.cn/paper/3872/problem/3539/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int n;

    public static void main(String[] args) {
        n = sc.nextInt();
        // 需要买的
        PriorityQueue<Integer> q1 = new PriorityQueue<>(Comparator.reverseOrder());
        // 免费拿的
        PriorityQueue<Integer> q2 = new PriorityQueue<>(Comparator.reverseOrder());
        for (int i = 1; i <= n; i++) q2.add(sc.nextInt());
        long res = 0;
        while (!q2.isEmpty() || !q1.isEmpty()) {
            // 取货
            int num = 0;
            // 最大值中的最小值
            int minV = (int) 2e9;
            // 数量少了就取
            while (num < 2 && !q1.isEmpty()) {
                int price = q1.poll();
                res += price;
                minV = Math.min(minV, price);
                num++;
            }
            // 数量少了就取
            while (num < 2 && !q2.isEmpty()) {
                int price = q2.poll();
                res += price;
                minV = Math.min(minV, price);
                num++;
            }
            // 数量为2的时候，去免费的那里取
            if (num == 2) {
                while (!q2.isEmpty()) {
                    int price = q2.poll();
                    // 免费就取
                    if (price <= minV / 2) {
                        break;
                    } else {
                        // 不免费就得买了
                        q1.add(price);
                    }
                }
            }
        }
        out.println(res);
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
